package org.wesc.boot.webapi;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
import org.springframework.boot.actuate.trace.http.InMemoryHttpTraceRepository;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.context.request.RequestContextListener;
import org.wesc.boot.dao.DaoConfiguration;
import org.wesc.boot.secure.SecureConfiguration;
import org.wesc.boot.service.ServiceConfiguration;

/**
 * @author Wesley
 */
@EnableAutoConfiguration
@Import({DaoConfiguration.class, SecureConfiguration.class, ServiceConfiguration.class})
@ComponentScan(basePackageClasses = { WebApplication.class })
@EnableScheduling
@EnableAsync
public class WebApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
    }

    @Bean
    public RequestContextListener requestContextListener(){
        return new RequestContextListener();
    }

    /**
     * 手动开启httpTrace监控
     */
    @ConditionalOnMissingBean
    @Bean
    public HttpTraceRepository httpTraceRepository() {
        return new InMemoryHttpTraceRepository();
    }

}
